package com.emm.yixun.openapi.hander;

import com.emm.yixun.common.app.CustomerCommDto;
import com.emm.yixun.common.app.EditCustomerIntentionReqDto;
import com.emm.yixun.common.app.EditCustomerIntentionResDto;
import com.emm.yixun.common.exception.XFUNExceptionCode;
import com.emm.yixun.config.CustomerUtil;
import com.emm.yixun.customer.service.app.CustomerServiceAppFacade;
import com.emm.yixun.openapi.dto.base.BaseRequestDTO;
import com.emm.yixun.openapi.dto.base.BaseResponseDTO;
import com.emm.yixun.openapi.hander.base.CommonAbstractHander;
import com.emm.yixun.openapi.vo.EditCustomerIntentionReqVo;
import net.sf.ehcache.CacheManager;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 编辑客户信息，验证客户参数是否满足意向等级
 * Created by Administrator on 2017/8/11.
 */
@Service("editCustomerIntentionHander")
public class EditCustomerIntentionHander extends CommonAbstractHander{
    @Autowired
    private CustomerServiceAppFacade customerServiceAppFacade;
    @Autowired
    private CacheManager cacheManager;

    @SuppressWarnings("rawtypes")
    @Override
    public BaseResponseDTO doBusiness(BaseRequestDTO reqDto) {
        EditCustomerIntentionReqVo req = (EditCustomerIntentionReqVo)reqDto;
        EditCustomerIntentionReqDto reqDto1 = req.getParams();
        CustomerCommDto dto = CustomerUtil.checkIntentionLevel(reqDto1);
        reqDto1.setIsIntentionIntact(dto.getIsIntentionIntact());
        reqDto1.setIntentionLevel(dto.getIntentionLevel());
        BaseResponseDTO<EditCustomerIntentionResDto> res = new BaseResponseDTO<EditCustomerIntentionResDto>();
        EditCustomerIntentionResDto resDto = new EditCustomerIntentionResDto();
        try{
            resDto = customerServiceAppFacade.editCustomerIntention(reqDto1);
        } catch (Exception e) {
            if("customer".equals(e.getMessage())){
                resDto.setErrorCode(XFUNExceptionCode.UNKNOW_EXCEPTON.getCode());
                resDto.setErrorMsg("修改客户操作失败");
                resDto.setResult("0");
            }else if("houseType".equals(e.getMessage())){
                resDto.setErrorCode(XFUNExceptionCode.UNKNOW_EXCEPTON.getCode());
                resDto.setErrorMsg("修改客户关注户型操作失败");
                resDto.setResult("0");
            }else if("premises".equals(e.getMessage())){
                resDto.setErrorCode(XFUNExceptionCode.UNKNOW_EXCEPTON.getCode());
                resDto.setErrorMsg("修改客户意向组团操作失败");
                resDto.setResult("0");
            }else if("room".equals(e.getMessage())){
                resDto.setErrorCode(XFUNExceptionCode.UNKNOW_EXCEPTON.getCode());
                resDto.setErrorMsg("修改客户意向房号操作失败");
                resDto.setResult("0");
            }else if("family".equals(e.getMessage())){
                resDto.setErrorCode(XFUNExceptionCode.UNKNOW_EXCEPTON.getCode());
                resDto.setErrorMsg("修改客户家庭成员操作失败");
                resDto.setResult("0");
            }else{
                resDto.setErrorCode(XFUNExceptionCode.UNKNOW_EXCEPTON.getCode());
                resDto.setErrorMsg(XFUNExceptionCode.UNKNOW_EXCEPTON.getDesout());
                resDto.setResult("0");
            }
        }
        res.setResData(resDto);
        return res;
    }
}
